package org.argeproje.resim.proc;

import javax.media.jai.TiledImage;

import org.argeproje.resim.proc.data.Data;
import org.argeproje.resim.proc.data.ImageDA;



/*
Definition
  Calls PerPixelFunction for each pixel. 
Inputs
  ImageDA
Parameters
  PerPixelFunction: Class instance that implements PerPixelFunction interface.
Outputs
  ImageDA
 */
public class FunctionPR extends Processor {
	protected PerPixelFunctionI _perPixelFunction;
	protected int _dataType;
	public void setParameters(PerPixelFunctionI function){
		setParamPerPixelFunction(function);
	}
    public void setParamPerPixelFunction(PerPixelFunctionI function){
       _perPixelFunction = function;	
    }
    public PerPixelFunctionI getParamPerPixelFunction(){
    	return _perPixelFunction;
    }
	public Data process() {
		ImageDA in = getInputAsImageDA();
		ImageDA out = new ImageDA(in);
		out.setWritable();
		int height = out.getHeight();
		int width = out.getWidth();
		int nBand = out.getNBands();
		TiledImage im = (TiledImage) out.getData();
		for (int h = 0; h < height; h++)
			for (int w = 0; w < width; w++) {
				for (int band = 0; band < nBand; band++){
						float value = im.getSample(w, h, band);
						value = _perPixelFunction.processSample(w, h, band, value);
						im.setSample(w, h, band, value);
					}
					
				}
		setOutput(out);
		return getOutput();
	}

}
